﻿using Data;
using Sirenix.OdinInspector;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Xml.Serialization;
using UnityEngine;

public class ActionBaseData : MonoBehaviour
{

    #region 动作
    [VerticalGroup("Split")]
    [FoldoutGroup("Split/动作", false), LabelText("动作版本")]
    public String ActionVersion = String.Empty;

    [FoldoutGroup("Split/动作", false), LabelText("动画版本")]
    public String AnimationVersion = String.Empty;

    [FoldoutGroup("Split/动作", false), LabelText("特效版本")]
    public String GfxVersion = String.Empty;

    [FoldoutGroup("Split/动作", false), LabelText("动作ID")]
    public String ID = "N0000";

    [Description("动作的总时间为[AnimTime+PoseTime](单位毫秒)")]
    [DisplayName("动作的总时间")]
    [DefaultValue(0)]
    public int TotalTime { get { return AnimTime + PoseTime; } }

    [FoldoutGroup("Split/动作", false), LabelText("动作名称")]
    public String Name = "未命名";

    [FoldoutGroup("Split/动作", false), LabelText("动作描述")]
    public String Desc = "动作";

    [FoldoutGroup("Split/动作", false), LabelText("缺省连接的动作ID号")]
    public String DefaultLinkActionID = "N0000";

    [FoldoutGroup("Split/动作", false) , LabelWidth(300),LabelText("1秒里面动作移动的速度(单位厘米)")]
    public int MoveSpeed = 0;

    [FoldoutGroup("Split/动作", false) , LabelWidth(300),LabelText("动画播放完成之后Blend到POSE的时间(单位毫秒)")]
    public int PoseTime = 0;

    [FoldoutGroup("Split/动作", false) , LabelWidth(300),LabelText("动画的时间(单位毫秒)")]
    public int AnimTime = 1000;

    [FoldoutGroup("Split/动作", false) , LabelWidth(300),LabelText("动画转换到其他动画时候的混合时间，默认为100(单位毫秒)")]
    public int BlendTime = 100;


    [FoldoutGroup("Split/动作", false), LabelText("动画列表")]
    public List<AnimSlot> AnimSlotList = new List<AnimSlot>();

    #endregion

    #region 包围盒

    [FoldoutGroup("Split/包围盒", false), LabelText("包围盒的偏移，单位为厘米"), Space(15)]
    public UnityEngine.Vector3 BoundingOffset;

    [FoldoutGroup("Split/包围盒", false), LabelText("包围盒的长度比例调整"), Space(5)]
    public UnityEngine.Vector3 BoundingRadio;


    [FoldoutGroup("Split/包围盒", false), LabelText("碰撞框的长度比例调整"), Space(5)]
    public UnityEngine.Vector3 CollisionRadio;

    [FoldoutGroup("Split/包围盒", false), LabelText("碰撞框的偏移比例调整"), Space(5)]
    public UnityEngine.Vector3 CollisionOffset;

    #endregion

    #region 状态
    static ValueDropdownList<int> HeightStatusMap = new ValueDropdownList<int>() {
            {" 站立 "  ,   0 },
            {" 地面 "  ,   1 },
            {" 低空 "  ,   2 },
            {" 高空 "  ,   3 },
            {" 被抓 "  ,   4 },
        };
    static ValueDropdownList<int> ActionStatusMap = new ValueDropdownList<int>() {
            {" 站立 "  ,   0 },
            {" 待机 "  ,   0 },
            {" 移动 "  ,   1 },
            {" 攻击 "  ,   2 },
            {" 受伤 "  ,   3 },
            {" 防御 "  ,   4 },
        };
    static ValueDropdownList<int> FragmentStatusMap = new ValueDropdownList<int>() {
            {" 准备 "  ,   0 },
            {" 行动 "  ,   1 },
            {" 回复 "  ,   2 },
            {" 硬直 "  ,   3 },
        };

    [FoldoutGroup("状态", false),LabelText("高度状态"), ValueDropdown("HeightStatusMap")]
    public int HeightStatus = 0;

    [FoldoutGroup("状态", false), LabelText("动作状态"), ValueDropdown("ActionStatusMap")]
    public int ActionStatus = 0;

    [FoldoutGroup("状态", false), LabelText("片段状态"), ValueDropdown("FragmentStatusMap")]
    public int FragmentStatus = 1;

    #endregion

    #region other

    [FoldoutGroup("基础", false), LabelText("动作等级"), PropertyTooltip("动作等级(动作等级为0的时候，该动作采用单位的默认动作，否则为指定的设定等级。默认值为0)")]
    public int ActionLevel = 0;

    [FoldoutGroup("基础", false), LabelText("是否重置速度")]
    public bool ResetVelocity = true;

    [FoldoutGroup("基础", false), LabelText("是否生成碰撞")]
    public int HasCollision = 0;

    [FoldoutGroup("基础", false), LabelText("受击后转向")]
    public int RotateOnHit = 0;

    //[FoldoutGroup("基础", false), LabelText("ActionCache")]
    //public int ActionCache = 0;

    //[FoldoutGroup("基础", false), LabelText("NextActionCache")]
    //public int NextActionCache = 0;

    #endregion

    #region CATEGORY_CONTROLLER

    [FoldoutGroup("控制器", false), LabelText("空中(切换玩家状态到：空中)"), LabelWidth(300)]
    public bool IgnoreGravity = false;

    [FoldoutGroup("控制器", false), LabelText("面向目标"), LabelWidth(300)]
    public bool FaceTarget = false;

    [FoldoutGroup("控制器", false), LabelText("可移动(切换玩家状态到：可移动)"), LabelWidth(300)]
    public bool CanMove = false;

    [FoldoutGroup("控制器", false), LabelText("可转身(切换玩家状态到：可转身)"), LabelWidth(300)]
    public bool CanRotate = false;

    [FoldoutGroup("控制器", false), LabelText("可受伤(切换玩家状态到：可受伤)"), LabelWidth(300)]
    public bool CanHurt = false;

    [FoldoutGroup("控制器", false), LabelText("无敌(切换玩家状态到：无敌)"), LabelWidth(300)]
    public bool IsGOD = false;

    [FoldoutGroup("控制器", false), LabelText("可穿透(切换玩家状态到：可穿透)"),LabelWidth(300)]
    public bool IsPenetrate = false;

    [FoldoutGroup("控制器", false), LabelText("摄像机视角"), LabelWidth(300)]
    public bool CameraTarget = false;

    #endregion

    [ActionInspectorButton]
    public ActionBaseData actionBaseData;
    private void OnEnable()
    {
        actionBaseData = this;
    }
    private Data.Action action;
    public void SetData(Data.Action action)
    {
        this.action = action;

        #region 动作
        ActionVersion = action.ActionVersion;
        AnimationVersion = action.AnimationVersion;
        GfxVersion = action.GfxVersion;
        ID = action.ID;
        Name = action.Name;
        Desc = action.Desc;
        DefaultLinkActionID = action.DefaultLinkActionID;
        MoveSpeed = action.MoveSpeed;
        PoseTime = action.PoseTime;
        AnimTime = action.AnimTime;
        BlendTime = action.BlendTime;
        AnimSlotList = action.AnimSlotList;
        #endregion

        #region 包围盒
        //unity 里填的单位m ， 保存的厘米
        BoundingOffset = new UnityEngine.Vector3(action.BoundingOffsetX / 100f, action.BoundingOffsetY / 100f, action.BoundingOffsetZ / 100f);
        //缩放值 scale * 100
        BoundingRadio = new UnityEngine.Vector3(action.BoundingLengthRadio / 100f, action.BoundingHeightRadio / 100f, action.BoundingWidthRadio / 100f);

        // 1 * 100
        CollisionOffset = new UnityEngine.Vector3(action.CollisionOffsetX / 100f, action.CollisionOffsetY / 100f, action.CollisionOffsetZ / 100f);
        CollisionRadio = new UnityEngine.Vector3(action.CollisionLengthRadio / 100f, action.CollisionHeightRadio / 100f, action.CollisionWidthRadio / 100f);

        #endregion

        #region 状态
        HeightStatus = action.HeightStatus;
        ActionStatus = action.ActionStatus;
        FragmentStatus = action.FragmentStatus;
        #endregion

        #region other
        ActionLevel = action.ActionLevel;
        ResetVelocity = action.ResetVelocity;
        HasCollision = action.HasCollision;
        RotateOnHit = action.RotateOnHit;
        //ActionCache = action.ActionCache;
        //NextActionCache = action.NextActionCache;
        #endregion

        #region CATEGORY_CONTROLLER
        IgnoreGravity =  action.IgnoreGravity;
        FaceTarget = action.FaceTarget;
        CanMove = action.CanMove;
        CanRotate = action.CanRotate;
        CanHurt = action.CanHurt;
        IsGOD = action.IsGOD;
        IsPenetrate = action.IsPenetrate;
        CameraTarget = action.CameraTarget;
        #endregion

    }
    public void SaveData()
    {
        #region 动作
        action.ActionVersion = ActionVersion ;
        AnimationVersion = action.AnimationVersion ;
        action.GfxVersion = GfxVersion;
        action.ID = ID;
        action.Name = Name ;
        action.Desc = Desc;
        action.DefaultLinkActionID = DefaultLinkActionID ;
        action.MoveSpeed = MoveSpeed;
        action.PoseTime = PoseTime;
        action.AnimTime = AnimTime;
        action.BlendTime = BlendTime;
        action.AnimSlotList = AnimSlotList ;
        #endregion

        #region 包围盒
        //unity 里填的单位m ， 保存的厘米
        action.BoundingOffsetX =(int)(BoundingOffset.x * 100);
        action.BoundingOffsetY = (int)(BoundingOffset.y * 100);
        action.BoundingOffsetZ = (int)(BoundingOffset.z * 100);

        action.BoundingLengthRadio = (int)(BoundingRadio.x * 100);
        action.BoundingHeightRadio = (int)(BoundingRadio.y * 100);
        action.BoundingWidthRadio = (int)(BoundingRadio.z * 100);

        action.CollisionOffsetX = (int)(CollisionOffset.x * 100);
        action.CollisionOffsetY = (int)(CollisionOffset.y * 100);
        action.CollisionOffsetZ = (int)(CollisionOffset.z * 100);

        action.CollisionLengthRadio = (int)(CollisionRadio.x * 100);
        action.CollisionHeightRadio = (int)(CollisionRadio.y * 100);
        action.CollisionWidthRadio = (int)(CollisionRadio.z * 100);
        #endregion

        #region 状态
        action.HeightStatus = HeightStatus;
        action.ActionStatus = ActionStatus;
        action.FragmentStatus = FragmentStatus;
        #endregion

        #region other
        action.ActionLevel = ActionLevel;
        action.ResetVelocity = ResetVelocity;
        action.HasCollision = HasCollision;
        action.RotateOnHit = RotateOnHit;
        //action.ActionCache = ActionCache;
        //action.NextActionCache = NextActionCache;
        #endregion

        #region CATEGORY_CONTROLLER
        action.IgnoreGravity = IgnoreGravity;
        action.FaceTarget = FaceTarget ;
        action.CanMove = CanMove;
        action.CanRotate = CanRotate;
        action.CanHurt = CanHurt;
        action.IsGOD = IsGOD;
        action.IsPenetrate = IsPenetrate;
        action.CameraTarget = CameraTarget;
        #endregion

        //TODO 刷新面板 Action 状态信息界面
        EventManager.TriggerEvent(CommonEvent.OnOneActionDataRefreshActionInspector);
    }
}
